//@include "lib.jsx"
// 获取当前活动文档
var doc = app.activeDocument;
var dName = removeFileExtension(getCurrentDocumentName())

// 修改所有图层名称为"ref"的文本图层的内容为"11"
modifyTextLayersContent(doc, "ref", dName);

// 在文档中递归查找并修改文本图层的内容
function modifyTextLayersContent(container, layerName, newTextContent) {
    for (var i = 0; i < container.layers.length; i++) {
        var currentLayer = container.layers[i];

        if (currentLayer.typename === "LayerSet") {
            // 如果是图层组，递归调用
            modifyTextLayersContent(currentLayer, layerName, newTextContent);
        } else if (currentLayer.typename === "ArtLayer" && currentLayer.name === layerName && currentLayer.kind === LayerKind.TEXT) {
            // 如果是文本图层，修改内容
            currentLayer.textItem.contents = newTextContent;
        }
    }
}